

// --------------------- 切换登录和注册的盒子 --------------------
$('.login a').on('click',function () {
  $('.register').show();
})



$('.register a').on('click',function () {
  $('.register').hide();
})

// 登录
$('.login form').on('submit', function (e) {
  e.preventDefault();
  let data = $(this).serialize();
  
  axios.post('/api/login',data).then(res=>{
    let {status,message,token}= res.data ;
    if (status ===0){
      localStorage.setItem('token',token);
      layer.msg(message,{ tiem:1500},()=>{
        location.href ='./index.html';
      })
    }
  })
})

// 注册
$('.register form').on('submit',function (e) {
  e.preventDefault();
  let data = $(this).serialize();

  axios.post('/api/reguser',data).then(res=>{
    let {status,message}=res.data;
    if(status === 0){
      layer.msg(message)
      $('.register form')[0].reset();
      $('.register').hide();
    }
  })
});

    // 验证密码
    let form =layui.form;
    form.verify({
      len: [/^\S{6,12}$/,'长度为6~12位且不能有空格'],
      same:function (val) {
        let pwd = $('.pwd').val();
        if(pwd!== val) return '两次输入密码不一致'
      }
    })